package util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * json帮助类
 * 提供序列化与反序列化
 * 使用jackson实现
 *
 * @author wyl
 */
public final class JsonHelper {
    private static final ObjectMapper mapper = new ObjectMapper();

    public static String toJson(Object obj) throws JsonProcessingException {
        return mapper.writeValueAsString(obj);
    }

    public static <T> T jsonToObject(String json, Class<T> type) throws JsonProcessingException {
        return mapper.readValue(json, type);
    }
}
